﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Globalization;
using System.Text.RegularExpressions;

namespace UIControls
{
    public class NameValidation : ValidationRule
    {
        public NameValidation()
        {
        }

        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            string name = value.ToString();
            Regex r = new Regex("^\\w$");

            if (r.IsMatch(name))
            {
                return new ValidationResult(false, null);
                //下面的return返回的参数在页面中可以通过TextBox的(ValidationErrors)[0].ErrorContent获取
                //return new ValidationResult(false, string.Format("年龄只能在{0}-{1}之间.", _min, _max));
            }
            else
            {
                return new ValidationResult(true, null);
            }
        }
    }
}
